package ControlLayer;

import static org.junit.Assert.*;

import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Calendar;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import DBLayer.GetMax;
import ExceptionLayer.CustomException;
import ModelLayer.Booking;
import ModelLayer.Employee;
import ModelLayer.Person;
import ModelLayer.Treatment;

public class BookingCtrTest {
	private BookingCtr bookCtr;
	
	@Before
	public void setUp() throws Exception {
		bookCtr = new BookingCtr();
		
		Treatment treat = new Treatment();
		treat.setEstimatedTime(15);
		
		bookCtr.getTempBooking().setTreatment(treat);
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testGetAvailableTimes() {
		try
		{
			Calendar cal = Calendar.getInstance();
			
			ArrayList<Employee> emps = bookCtr.getAvailableTimes(new Date(cal.getTimeInMillis()));
			
			for(Employee emp : emps)
			{
				System.out.println(emp.getFirstName());
				
				for(String availTime : emp.getAvailableTimes())
				{
					System.out.println(availTime);
				}
			}
		}
		catch(Exception err)
		{
			fail("Not yet implemented");
		}
	}
	
	@Test
	public void createBooking()
	{
		BookingCtr bookCtr = new BookingCtr();
		
		Booking tempBooking = bookCtr.getTempBooking();
		
		tempBooking.setId(GetMax.getMaxId("SELECT MAX(ID) FROM Product"));
		
		Treatment treat = new Treatment();
		treat.setId(1);
		
		tempBooking.setTreatment(treat);
		
		Employee emp = new Employee();
		emp.setId(1);
		
		tempBooking.setHairDresser(emp);
		
		Person cust = new Person();
		cust.setId(2);
		
		tempBooking.setCustomer(cust);
		
		tempBooking.setDate(new Date(113, 4, 30));
		tempBooking.setStartTime(new Time(9, 0, 0));
		tempBooking.setEndTime(new Time(10, 0, 0));
		tempBooking.setStatus("oprettet");
		
		try
		{
			bookCtr.createBooking();
			
			System.out.println("Bookingen blev oprettet!");
		}
		catch(CustomException err)
		{
			System.out.println(err.getMessage());
		}
	}

}
